package ar.com.drconta.ganancias.views.code;

import java.util.ArrayList;

import java.util.List;
 

 

 
public class Team {
 
        
 
        public static final int MAX_MEMBER_COUNT = 5;
 
        
 
        private Person[] teamMembers = new Person[MAX_MEMBER_COUNT];
 
        
 
        public boolean addMember(Person member) {
 
                boolean addSuccess = false;
 
                if(null == member) return addSuccess;
 
                if(isFull()) return addSuccess;
 
                for (int i = 0; i < teamMembers.length; i++) {
 
                        if(null == teamMembers[i]) {
 
                                member.setTeam(this);
 
                                teamMembers[i] = member;
 
                                addSuccess = true;
 
                                break;
 
                        }
 
                }
 
                return addSuccess;
 
        }
 
        
 
        public Person[] getAllMember() {
 
                List<Person> result = new ArrayList<Person>();
 
                for (Person p : teamMembers) {
 
                        if(null != p) {
 
                                result.add(p);
 
                        }
 
                }
 
                return result.toArray(new Person[0]);
 
        }
 
        
 
        public boolean isFull() {
 
                int index = 0;
 
                for (Person eachMember : teamMembers) {
 
                        if(null != eachMember) {
 
                                index++;
 
                        }
 
                }
 
                return index >= MAX_MEMBER_COUNT;
 
        }
 
}
 
